package com.taldh.algorithm.回溯算法;

import org.junit.Assert;
import org.junit.Test;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;

public class LetterCombinations {

    private static HashMap<Character, String> map = new HashMap<>();
    static {
        map.put('2',"abc");
        map.put('3',"def");
        map.put('4',"ghi");
        map.put('5',"jkl");
        map.put('6',"mno");
        map.put('7',"pqrs");
        map.put('8',"tuv");
        map.put('9',"wxyz");
    }

    public List<String> letterCombinations(String digits) {
        if (digits == null || digits.length() == 0) {
            return null;
        }
        int arrayLength = 1;
        char[] digitsChars = digits.toCharArray();
        int length = digitsChars.length;
        String[] arrayStr = new String[length];
        for (int i = 0; i < length; i++) {
            char digitsChar = digitsChars[i];
            arrayLength *= map.get(digitsChar).length();
            arrayStr[i] = map.get(digitsChar);
        }
        List<String> ans = new ArrayList<>(arrayLength);
        for (int i = 0; i < arrayLength; i++) {
            StringBuilder sb = new StringBuilder(length);
            for (int j = 0; j < length; j++) {
                //sb.append(arrayStr[j].substring());
            }
            ans.add(sb.toString());
        }
        return ans;
    }

    @Test
    public void test() {
        //Assert.assertArrayEquals(letterCombinations("23"), Arrays.asList("ad", "ae", "af", "bd", "be", "bf", "cd", "ce", "cf"));
    }
}